# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: Daenyth <Daenyth+Arch [AT] gmail [DOT] com>
# Contributor: djnm <nmihalich [at} gmail dott com>

pkgname=dwarffortress
pkgver=0.47.05
_pkgver=47_05
pkgrel=3
pkgdesc="A single-player fantasy game in which you build a dwarven outpost or play an adventurer in a randomly generated world"
arch=('loong64' 'x86_64')
url="https://www.bay12games.com/dwarves/"
license=('custom:dwarffortress')
depends=('libice' 'gtk3' 'glu' 'sdl' 'sdl_image' 'sdl_ttf' 'libsndfile'
         'libsm'  'openal' 'glew' 'gcc-libs' 'glib2')
makedepends=('git' 'cmake')
optdepends=('nvidia-utils: If you have nvidia graphics'
            'alsa-lib: for alsa sound'
            'libpulse: for pulse sound')
options=('!strip' '!buildflags')
install=$pkgname.install
# I made a github repo for the sole purpose of cleaning up df a bit
# We try to compile whatever little bit of df is open source
source=(git+https://github.com/svenstaro/dwarf_fortress_unfuck.git#tag=${pkgver}
        dwarffortress
        dwarffortress.desktop
        dwarffortress.png
        https://www.bay12games.com/dwarves/df_${_pkgver}_linux.tar.bz2)
sha256sums=('SKIP'
            '8c719b8922ce8dcb3173ec035938d0271e6ba6d73795b246bfb313494adb5a38'
            'e79e3d945c6cc0da58f4ca30a210c7bf1bc3149fd10406d1262a6214eb40445a'
            '83183abc70b11944720b0d86f4efd07468f786b03fa52fe429ca8e371f708e0f'
            'ac74a6dbb7d7d9621f430405080322ab50c35f6632352ff2ea923f6dc5affca3')

build() {
  cd dwarf_fortress_unfuck

  cmake .
  make
}

package() {
  install -dm755 "$pkgdir"/opt/
  cp -r "$srcdir"/df_linux "$pkgdir"/opt/$pkgname
  rm -r "$pkgdir"/opt/$pkgname/df "$pkgdir"/opt/$pkgname/libs/* "$pkgdir"/opt/$pkgname/g_src

  find "$pkgdir"/opt/$pkgname -type d -exec chmod 755 {} +
  find "$pkgdir"/opt/$pkgname -type f -exec chmod 644 {} +

  install -Dm755 "$srcdir"/df_linux/libs/Dwarf_Fortress "$pkgdir"/opt/$pkgname/libs/Dwarf_Fortress
  install -Dm755 "$srcdir"/dwarf_fortress_unfuck/libgraphics.so "$pkgdir"/opt/$pkgname/libs/libgraphics.so
  install -Dm755 "$srcdir"/dwarffortress "$pkgdir"/usr/bin/$pkgname

  # No idea why we need this. Really. This isn't being loaded dynamically, it's not linked and
  # in general there is no indication this is being used. However, it doesn't work without this symlink.
  ln -s /usr/lib/libpng.so "$pkgdir"/opt/$pkgname/libs/libpng.so.3

  # Set pkgname in runscript
  sed -i "s/^pkgname=.*/pkgname=$pkgname/" "$pkgdir"/usr/bin/$pkgname

  # Desktop launcher with icon
  install -Dm644 "$srcdir"/dwarffortress.desktop "$pkgdir"/usr/share/applications/"$pkgname".desktop
  install -Dm644 "$srcdir"/dwarffortress.png     "$pkgdir"/usr/share/pixmaps/"$pkgname".png

  install -Dm644 "$srcdir"/df_linux/readme.txt "$pkgdir"/usr/share/licenses/$pkgname/readme.txt
}

# vim:set ts=2 sw=2 et:
